<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" name="viewport" content="width-device-width,initial-scale=1">
    <title>长流博客</title>
    <script src="/js/jquery.min.js"></script>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/ajaxGetHtml.js"></script>
    <script>
        function getActicleByName() {
            $.ajax({
                type: 'POST',
                contentType: 'application/json;charset=utf-8',
                url: '/MEditor/getBlogByUserName/'+sessionStorage.sessionId,
                dataType: 'json',
                success: function (data) {
                    var result = data['message'];
                    if(result=="获取成功"){
                        var blog = data['result'];
                        var newsList = $("#newsList");
                        for (let i in blog){
                            let article = blog[i];
                            newsList.append('<li class="list-group-item" id="'+blog[i]['id']+'">' +
                                '<a onclick="deleteArticle('+blog[i]['id']+')" class="btn btn-default">删除</a> ' +
                                '<a onclick="updateArticle('+blog[i]['id']+')" class="btn btn-default">修改</a> ' +
                                '<a onclick="showArticle('+blog[i]['id']+')">标题：<span id="title"> '+blog[i]['title']+'</span></a>' +
                                '<span class="label label-info" style="float:right" id="clickNum">'+article["clickNum"]+'</span>' +
                                '</li>')
                            if(blog[i]['editorType']=='1'){
                                $('#'+blog[i]['id']).append('<span class="label label-success" style="float:right" id="'+blog[i]['id']+'newsType">UE</span>')
                            }else {
                                $('#'+blog[i]['id']).append('<span class="label label-primary" style="float:right" id="'+blog[i]['id']+'newsType">MD</span>')
                            }
                        }
                    }
                },
                error: function (err) {
                    alert(JSON.stringify(err));
                }
            });
        }
        function deleteArticle(id) {
            $.ajax({
                type: 'POST',
                contentType: 'application/json;charset=utf-8',
                url: '/MEditor/delete/'+id+'/'+sessionStorage.sessionId,
                dataType: 'json',
                success: function (data) {
                    alert(data['message']);
                },
                error: function (err) {
                    alert(JSON.stringify(err));
                }
            });
            insteadSafe('/MEditor/manageBlog','#instead')
        }
        function updateArticle(id) {
            var newsType = $('#'+id+'newsType').html();
            if (newsType=='UE')
                getHttp("/UEditor/updateBlog/"+id);
            else if(newsType=='MD')
                getHttp("/MEditor/updateBlog/"+id);
        }
        function showArticle(id){
            $(location).attr('href','/home/showBlog/'+id);
        }
        $(function () {
            getActicleByName();
        })
    </script>
</head>
<body>
<div th:replace="public/header"></div>
<div class="container">
    <ul class="list-group" id="newsList">
<!--        <li class="list-group-item">-->
<!--            <a href="" class="btn btn-default">删除</a>-->
<!--            <a href="" class="btn btn-default">修改</a>-->
<!--            <a href="">标题：<span id="title"></span></a>-->
<!--            <span class="label label-info" style="float:right" id="clickNum"></span>-->
<!--        </li>-->
    </ul>
</div>
<div th:replace="public/footer"></div>
</body>
</html>